﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Breeds;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Breeds
{
    public class AddBreedCommandHandLer : IRequestHandler<AddBreedCommand, APIResult<int>>
    {


        private readonly IBaseRepostiy<Breed> _breed;
        private readonly IMapper mapper;

        public AddBreedCommandHandLer(IBaseRepostiy<Breed> breed, IMapper mapper)
        {
            _breed = breed;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(AddBreedCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<Breed>(request);
            var res = await _breed.AddAsync(list);
            result.Code = ResultCode.Ok;
            result.Message = "商品信息添加成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
